package Thread;

import java.util.Scanner;

public class PasswordGenerator {
    private static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();  // 读取测试数据组数

        while (T-- > 0) {
            int n = scanner.nextInt();  // 原始密码长度
            String s = scanner.next();  // 原始密码字符串

            // 找到原始密码的最大值和最小值
            int maxDigit = 0;
            int minDigit = 9;
            for (char c : s.toCharArray()) {
                int digit = c - '0';
                maxDigit = Math.max(maxDigit, digit);
                minDigit = Math.min(minDigit, digit);
            }

            // 计算总的密码数量：每位可以是0-9中的任意一个，总数为 10^n
            long totalCombinations = modPow(10, n, MOD);

            // 计算没有比最大值更大的数字的组合：即所有位的数字都 <= maxDigit
            long combinationsLessThanMax = modPow(maxDigit + 1, n, MOD);

            // 计算没有比最小值更小的数字的组合：即所有位的数字都 >= minDigit
            long combinationsGreaterThanMin = modPow(10 - minDigit, n, MOD);

            // 计算既没有比最大值大的数字也没有比最小值小的数字的组合
            long invalidCombinations = modPow(maxDigit - minDigit + 1, n, MOD);

            System.out.println("totalCombinations: " + totalCombinations);
            System.out.println("combinationsLessThanMax: " + combinationsLessThanMax);
            System.out.println("combinationsGreaterThanMin: " + combinationsGreaterThanMin);

            // 结果：总的组合数减去无效的组合数
            long result = (totalCombinations - combinationsLessThanMax - combinationsGreaterThanMin + invalidCombinations) % MOD;
            System.out.println(result);
        }

        scanner.close();
    }

    // 快速幂计算 (a^b % mod)
    private static long modPow(long base, long exp, long mod) {
        long result = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) {
                result = (result * base) % mod;
            }
            base = (base * base) % mod;
            exp >>= 1;
        }
        return result;
    }
}

